import commonConstants from '@/common/constants/commonConstants.js'

import requestUrl from '@/common/constants/requestUrl.js'
import {
	encrypt,
	decrypt
} from '@/common/js/des.js'

export default {
	// 上传图片
	uploadImage(filePath, success, error) {
		uni.uploadFile({
			url: commonConstants.request.resourceUrl + commonConstants.request.context.path.system +
				'/uploadFile/ems', //仅为示例，非真实的接口地址
			filePath: filePath,
			name: 'file',
			header: {
				Authorization: decrypt(uni.getStorageSync('token'), 3)
			},
			formData: {
				user: uni.getStorageSync("userInfo").userCode
			},
			success: res => {
				//对于返回数据的处理，根据实际情况调整
				let data = JSON.parse(res.data)
				if (data.success) {
					if (success) {
						success(data.list[0])
					}
				} else {
					uni.showToast({
						title: "图片上传失败",
						icon: 'none'
					})
					if (error) {
						error(data.message)
					}
				}
			},
			fail: res => {
				console.log(res);
				if (error) {
					error(res)
				}
			}
		})

	},
	/**
	 * 文件上传 

	 * @param {Object} filePath  文件路径
	 * @param {Object} angel 旋转角度
	 * @param {Object} success 成功回调
	 * @param {Object} error 失败回调
	 */
	doRotatingUploadPicture(filePath, angel, success, error) {
		console.log("文件上传:" + filePath, "====旋转角度:" + angel);
		uni.uploadFile({
			url: commonConstants.request.resourceUrl + commonConstants.request.context.path.ems +
				'/ems/eSign/doRotatingUploadPicture?sign=123&languageType=zh_CN', //仅为示例，非真实的接口地址
			filePath: filePath,
			name: 'file',
			header: {
				Authorization: decrypt(uni.getStorageSync('token'), 3)
			},
			formData: {
				user: uni.getStorageSync("userInfo").userCode,
				angel: angel,
				file: filePath
			},
			success: res => {
				
				//对于返回数据的处理，根据实际情况调整
				let data = JSON.parse(res.data)
				if (data.success) {
					if (success) {
						success(data.list[0])
					}
				} else {
					uni.showToast({
						title: "图片上传失败",
						icon: 'none'
					})
					if (error) {
						error(data.message)
					}
				}
			},
			fail: res => {
				console.log(res);
				if (error) {
					error(res)
				}
			}
		})
	}
}